#ifndef SOCKET_H
#define SOCKET_H

#include <netinet/in.h>

/**
 * @brief Class wrapper around a Unix Socket
 */
class Socket {

public:
  Socket();
  ~Socket();

  bool Create();
  bool Bind(unsigned short port);
  bool Listen();
  bool Accept(Socket& new_socket) const;
  bool Connect(const char* host, unsigned short port);
  int Send(const void* buffer, size_t size) const;
  int Receive(void* buffer, size_t size) const;
  bool SetReceiveTimeoutInSec(int sec);
  bool Close();

  void set_sock_fd(int sock_fd);
  sockaddr_in sock_addr();
  int sock_fd();

private:
  int sock_fd_;
  sockaddr_in sock_addr_;

  /**
   * @brief Max Listen Queue Length.
   * Initialized in socket.cpp
   */
  static const int LISTEN_Q_LENGTH;

  /* Disallow copy and assignment. */
  Socket(const Socket& socket);
  Socket& operator=(const Socket& socket);

};

#endif
